/* 
 *  Copyright (c) 2011—2013 Panguso.com. All rights reserved. 
 *  File Name:  ActivityAbstractReadServiceImpl.java                                      
 *  File Contents Outline : 活动抽象
 *  File  Create Date:   2012年7月30日
 *  File Version#: Revision#: #1                  
 *  File  Latest Modify Date : 2013年1月16日
 *  File Author :  bachuan@panguso.com
 */
package cn.edu.thu.log.web.service.impl;

import cn.edu.thu.log.activity.abstraction.FromActivityTagXMLToTree;
import cn.edu.thu.log.tree.ManyTree;
import cn.edu.thu.log.tree.ManyTreeNode;
import cn.edu.thu.log.web.service.ActivityAbstractReadService;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jdom.Element;
import org.jdom.JDOMException;

/**
 *
 * @author wan
 */
public class ActivityAbstractReadServiceImpl implements ActivityAbstractReadService{
  private static ActivityAbstractReadService singleton = null; 
    private ManyTree manyTree;
    private String filename;
        
    public synchronized static ActivityAbstractReadService instance() {
        if (singleton == null) {
            singleton = new ActivityAbstractReadServiceImpl();
        }
        return singleton;
    }
    
    @Override
    public void readActivityConfig() {
               //获取日志清洗xml中的根节点     
        try {
            //创建ManyTree树
            FromActivityTagXMLToTree xmlTree = new FromActivityTagXMLToTree();
            //读取到xml中表示树的根节点
            Element treexmlroot = xmlTree.readActivityXML(filename);
            //生成多叉树
            ManyTreeNode treeroot = xmlTree.createTree(treexmlroot);
            manyTree = new ManyTree(treeroot);
//            if(manyTree.getRoot()==null){
//            System.out.println("null root");
//            }
//          System.out.printl("genjiedian:"+treeroot.getData().getKey());
     //       System.out.println("树的根节点：" + manyTree.getRoot().getData().getNodename());
     //       System.out.println("中序遍历结果：" + manyTree.iteratorTree(treeroot));
            //获得最小时间间隔和最大持续时间
//            min = xmlTree.getMinValue();
//            max = xmlTree.getMaxValue();

        } catch (JDOMException ex) {
            Logger.getLogger(ActivityAbstractReadServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    @Override
	public ManyTree getManyTree() {
        return manyTree;
    }

    /**
     * @param manytree the manytree to set
     */
    @Override
	public void setManyTree(ManyTree manyTree) {
        this.manyTree = manyTree;
    }

    @Override
    public void setActivityAbstractFileName(String filename) {
        this.filename=filename;
    }    
}
